package com.huawei

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object RDD {
    def main(args: Array[String]): Unit = {
        val conf = new SparkConf().setAppName("CollectOutInfo")
        val sc = new SparkContext(conf)
        sc.setLogLevel("WARN")
        val text = sc.textFile(args(0))
        // 过滤支持项目
        val data = text.filter(_.contains("out"))
        // 统计每个人的支出总和
        val result: RDD[(String, Int)] = data.map(line => {
            val t = line.split(",")
            (t(0), t(2).toInt)
        }).reduceByKey(_ + _)

        println("支出的结果统计为：")
        result.collect().map(x => x._1 + "," + x._2).foreach(println)
        sc.stop()
    }

}
